package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.saas.enums.business.ContractOutstockEnum;
import com.xbongbong.saas.enums.business.InvoiceEnum;
import com.xbongbong.saas.enums.business.PaymentTaskEnum;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 应收款 来源单据枚举
 * @author lee
 * @date 2019/5/1 17:14
 * @since v1.0
 * @version v1.0
 */
@Getter
public enum PaymentSourceTypeEnum {

    //应收款来源单据枚举
    //PAYMENT_TASK(FieldTypeEnum.SOURCE.getType(), "paymentTask",XbbRefTypeEnum.PAYMENT_TASK.getName(), XbbRefTypeEnum.PAYMENT_TASK.getCode(), PaymentTaskEnum.PAYMENT_TASK_NO.getAttr(), PaymentTaskEnum.PAYMENT_TASK_NO.getFieldType(), Arrays.asList(XbbRefTypeEnum.PAYMENT_TASK.getCode())),
    INVOICE(FieldTypeEnum.SOURCE.getType(), "invoice","enum.paymentSourceType.name.invoice", XbbRefTypeEnum.INVOICE.getCode(), InvoiceEnum.SHEET_NO.getAttr(), InvoiceEnum.SHEET_NO.getFieldType(), Arrays.asList(XbbRefTypeEnum.INVOICE.getCode())),

    OUTSTOCK(FieldTypeEnum.SOURCE.getType(), "outstock","enum.paymentSourceType.name.outstock", XbbRefTypeEnum.CONTRACT_OUTSTOCK.getCode(), ContractOutstockEnum.SHEET_NO.getAttr(), ContractOutstockEnum.SHEET_NO.getFieldType(), Arrays.asList(XbbRefTypeEnum.CONTRACT_OUTSTOCK.getCode())),
    ;

    private Integer fieldType;

    private String attr;

    private String name;

    private Integer businessType;

    private String linkAttr;

    private Integer linkFieldType;

    private List<Integer> businessTypeList;

    PaymentSourceTypeEnum(Integer fieldType, String attr, String name, Integer businessType, String linkAttr, Integer linkFieldType, List<Integer> businessTypeList) {
        this.fieldType = fieldType;
        this.attr = attr;
        this.name = name;
        this.businessType = businessType;
        this.linkAttr = linkAttr;
        this.linkFieldType = linkFieldType;
        this.businessTypeList = businessTypeList;
    }
    public static void getMapByFieldType(Integer fieldType, Map<String, String> map) {
        for (PaymentSourceTypeEnum paymentSourceTypeEnum : values()) {
            if (paymentSourceTypeEnum.getFieldType().equals(fieldType)) {
                map.put(paymentSourceTypeEnum.getAttr(), paymentSourceTypeEnum.getName());
            }
        }
    }

    public static PaymentSourceTypeEnum getByAttr(String attr) {
        for (PaymentSourceTypeEnum paymentSourceTypeEnum : values()) {
            if (paymentSourceTypeEnum.getAttr().equals(attr)) {
                return paymentSourceTypeEnum;
            }
        }
        return null;
    }

    public static PaymentSourceTypeEnum getByBusinessType(Integer linkBusinessType) {
        for (PaymentSourceTypeEnum cacheCode : values()) {
            if (cacheCode.getBusinessType().equals(linkBusinessType)) {
                return cacheCode;
            }
        }
        return INVOICE;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
